cmake_minimum_required(VERSION 3.0)
project(pyrtklib5)
set(CMAKE_CXX_STANDARD 17)

if(DEFINED PYTHON_INCLUDE_DIR AND NOT "${PYTHON_INCLUDE_DIR}" STREQUAL "")
    message(STATUS "Using python_include_dir from argument: ${PYTHON_INCLUDE_DIR}")
    include_directories(${PYTHON_INCLUDE_DIR})
else()
    message(STATUS "python_include_dir not provided. Using find_package(PythonLibs) instead.")
    find_package(PythonLibs REQUIRED)
endif()

add_subdirectory(pybind11)
include_directories(${PYBIND11_INCLUDE_DIRS})



ADD_DEFINITIONS(-DENACMP -DENAGAL -DENAGLO -DENAQZS -DENAIRN -DTRACE -DDLL -DEBUG)


if(DARWIN)
ADD_DEFINITIONS(-DDARWIN)
endif()

if(WIN32)
ADD_DEFINITIONS(-DWIN32)
endif()

set(CMAKE_VERBOSE_MAKEFILE ON)
set(LIBRARY OFF)
add_compile_options(-fno-stack-protector)
if(DEBUG)
    add_compile_options("-g")
else()
    add_compile_options("-O3")
endif()

include_directories("${PROJECT_SOURCE_DIR}/rtksrc/"  "${PROJECT_SOURCE_DIR}")
if(LIBRARY)
    ADD_SUBDIRECTORY(rtksrc)
    link_directories(${PROJECT_SOURCE_DIR}/build/lib)
    AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/rtksrc RTK_src)
    AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/rtksrc/rcv rcv_src)
    # add_library(pyrtklib MODULE pyrtklib.cpp)
    # target_link_libraries(pyrtklib PUBLIC rtk rcv pybind11::module  m pthread)
else()
    AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/rtksrc RTK_src)
    AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/rtksrc/rcv rcv_src)
    add_library(pyrtklib5 MODULE ${RTK_src} ${rcv_src} pyrtklib5.cpp) 
    # pybind11_add_module(pyrtklib NO_EXTRAS ${RTK_src} ${rcv_src} pyrtklib.cpp)
    if(WIN32)
        set_target_properties(pyrtklib5 PROPERTIES PREFIX "" SUFFIX ".pyd")
        target_link_libraries(pyrtklib5 PUBLIC pybind11::module winmm ws2_32)
    else()
        set_target_properties(pyrtklib5 PROPERTIES PREFIX "")
        target_link_libraries(pyrtklib5 PUBLIC pybind11::module m pthread)
    endif()
endif()
